package study.javase.io;


import java.io.*;

/**
 * 文件字符流 写入文件
 * @author LiShaowen
 * @date 2020/9/8 23:46
 */
public class FileWriterTest {
    public static void main(String[] args) {
        // 1.创建源
        File file = new File("src/main/java/study.javase/io/write.txt");
        // 2.选择流
        FileWriter writer = null;
        try {
            writer = new FileWriter(file,true);

            // 方式一
            String msg = "我是李少文";
            char[] datas = msg.toCharArray();
            writer.write(datas,0,datas.length);
            /*
            //方式二
            String msg = "我是李少文";
            writer.write(msg);*/

            /*
            // 方式三
            writer.append("我是").append("李少文");*/

            writer.flush();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (null!=writer) {
                try {
                    writer.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}
